package com.wl156.activities.messages;

import java.io.IOException;

import org.ksoap2.serialization.SoapObject;
import org.xmlpull.v1.XmlPullParserException;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListView;

import com.wl156.BaseActivity;
import com.wl156.MyApp;
import com.wl156.R;
import com.wl156.adapters.FeedManagerAdapter;
import com.wl156.model.Certificate;
import com.wl156.model.WebServiceClient;

public class ManageFeedInternal extends BaseActivity {

	ListView mList;

	private WebServiceClient mWebServiceClient;
	private Certificate mCertificate;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mWebServiceClient = new WebServiceClient(this);
		mCertificate = ((MyApp) getApplication()).getCertificateFromXml();

//		Window win = getWindow();
//		win.requestFeature(Window.FEATURE_LEFT_ICON);
		setContentView(R.layout.act_manage_feed_internal);
//		win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
//				R.drawable.ic_launcher);
		
		mList = (ListView) findViewById(R.id.list);

		new AsyncTask<Void, Void, Object>() {
			ProgressDialog mDialog;

			@Override
			protected void onPostExecute(Object result) {
				mDialog.dismiss();

				if (result instanceof Exception) {
					Exception e = (Exception) result;

				} else {
					SoapObject so = (SoapObject) result;
					SoapObject so0 = (SoapObject) so.getProperty(0);
					if (so0.getProperty(0).toString().equals("用户验证失败")) {

					} else {
						FeedManagerAdapter adapter = new FeedManagerAdapter(
								ManageFeedInternal.this, so);
						mList.setAdapter(adapter);
					}
				}
			};

			@Override
			protected void onPreExecute() {
				mDialog = ProgressDialog.show(ManageFeedInternal.this, "",
						"加载中...");
			};

			@Override
			protected Object doInBackground(Void... params) {
				try {
					return mWebServiceClient
							.common_getMySubscribe(mCertificate);
				} catch (IOException e) {
					e.printStackTrace();
					return e;
				} catch (XmlPullParserException e) {
					e.printStackTrace();
					return e;
				}
			}
		}.execute();
	}
}
